package com.woniuxy.his.exception;

import com.woniuxy.his.common.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandle {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandle.class);

    public GlobalExceptionHandle() {
    }

    @ExceptionHandler({ParamExceptionHandle.class})
    public Result handleBusinessException(ParamExceptionHandle e) {
        log.warn("执行失败，出现参数异常", e);
        return Result.fail("40005", "执行失败:" + e.getMessage(),null);
    }

    @ExceptionHandler({ReturnNoResultExceptionHandle.class})
    public Result handleNullResultException(ReturnNoResultExceptionHandle e) {
        log.error("执行失败，参数查询结果为null", e);
        return Result.fail("40000", "执行失败:" + e.getMessage(),null);
    }

    @ExceptionHandler({Exception.class})
    public Result handleSystemException(Exception e) {
        log.error("执行失败，出现系统异常", e);
        return Result.fail("40000", "执行失败:" + e.getMessage(),null);
    }



}
